#ifndef DRAWAREA_H
#define DRAWAREA_H

#include <QWidget>
#include <QLabel>
#include "InvertedPendulum.h"

class DrawArea : public QWidget {
    Q_OBJECT

public:
    DrawArea(QWidget *parent = nullptr);
    void setPendulum(InvertedPendulum *pendulum);
    void setControlLoopInterval(double interval); // 用于设置时间步的函数

public slots:
    void updatePendulum();
    void updateInfoLabel(); // 添加用于更新信息标签的槽函数

signals:
    void disturbanceApplied(double forceX, double forceTheta);

protected:
    QPointF dragStartPos;
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    QSize sizeHint() const;

private:
    InvertedPendulum *pendulum;
    bool isDragging;
    QPoint lastMousePos;
    QTimer *timer; // 用于更新loop的定时器
    double dt = 0.1; // 时间间隔

     QLabel *parameterLabel; // 用于显示参数的标签
     QTimer *infoLabelTimer; // 用于更新信息标签的定时器


};

#endif // DRAWAREA_H
